https://leetcode.cn/problems/flood-fill/description/
class Solution {
public:
    int m,n;
    int prev;
    int dx[4]={0,0,1,-1};
    int dy[4]={1,-1,0,0};
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        if(image[sr][sc]==color)
            return image;
        m=image.size(),n=image[0].size();
        prev=image[sr][sc];
        dfs(image,sr,sc,color);
        return image;
    }

    void dfs(vector<vector<int>>& image, int sr, int sc, int color)
    {
        image[sr][sc]=color;
        for(int i=0;i<4;i++)
        {
            int x=dx[i]+sr,y=dy[i]+sc;
            if(x>=0&&x<m&&y>=0&&y<n&&image[x][y]==prev)
            {
                 dfs(image,x,y,color);
            }
        }
    }
};